<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/views/global/taglibs.jsp" %>

<div class="row">
	<div class="col-md-6">
		<div class="panel panel-default">
 			<div class="panel-heading">
 				<div class="panel-title">Get</div>
 			</div>
 			<div class="panel-body">
 				<form id="getForm">
 					<div class="row navbar-form">
		  				<div class="form-group">
		  					<input type="text" class="form-control" name="key"
		  						 placeholder="please input the key" required="key is required.">
		  				</div>
		  				<button type="button" class="btn btn-success" onclick="saveNode('get')">Fetch</button>
		  				<span class="error"></span>
		  			</div>
		  			<textarea id="retValue" rows="4" cols="30" class="form-control"></textarea>
 				</form>
 			</div>
 		</div>
 		<div class="panel panel-default">
 			<div class="panel-heading">
 				<div class="panel-title">Set</div>
 			</div>
 			<div class="panel-body">
 				<form id="setForm">
 					<div class="row navbar-form">
		  				<div class="row">
		  					<div class="form-group">
			  					<input type="text" class="form-control" name="key"
			  						 placeholder="please input the key" required="key is required.">
			  				</div>
			  				<button type="button" class="btn btn-success" onclick="saveNode('set')">Save</button>
			  				<span class="error"></span>
		  				</div>
		  				<div class="row">
		  					<textarea rows="4" cols="30" name="value" class="form-control"
		  						placeholder="please input the value" required="value is required."></textarea>
		  				</div>
		  			</div>
		  			<span id="retValue"></span>
 				</form>
 			</div>
 		</div>
 		<div class="panel panel-default">
 			<div class="panel-heading">
 				<div class="panel-title">Delete</div>
 			</div>
 			<div class="panel-body">
 				<form id="getForm">
 					<div class="row navbar-form">
		  				<div class="form-group">
		  					<input type="text" class="form-control" name="key"
		  						 placeholder="please input the key" required="key is required.">
		  				</div>
		  				<button type="button" class="btn btn-success" onclick="saveNode('delete')">Delete</button>
		  				<span class="error"></span>
		  			</div>
		  			<textarea id="retValue" rows="4" cols="30" class="form-control"></textarea>
 				</form>
 			</div>
 		</div>
	</div>
	<div class="col-md-6">
		<div class="panel panel-default">
 			<div class="panel-heading">
 				<div class="panel-title">Hget</div>
 			</div>
 			<div class="panel-body">
 				<form id="hgetForm">
 					<div class="row navbar-form">
		  				<div class="form-group">
		  					<input type="text" class="form-control" name="key"
		  						 placeholder="please input the key" required="key is required.">
		  				</div>
		  				<div class="form-group">
		  					<input type="text" class="form-control" name="field"
		  						 placeholder="please input the field" required="field is required.">
		  				</div>
		  				<button type="button" class="btn btn-success" onclick="saveNode('hget')">Fetch</button>
		  				<span class="error"></span>
		  			</div>
		  			<textarea id="retValue" rows="4" cols="30" class="form-control"></textarea>
 				</form>
 			</div>
 		</div>
 		<div class="panel panel-default">
 			<div class="panel-heading">
 				<div class="panel-title">Hset</div>
 			</div>
 			<div class="panel-body">
 				<form id="hsetForm">
 					<div class="row navbar-form">
		  				<div class="row">
		  					<div class="form-group">
			  					<input type="text" class="form-control" name="key"
			  						 placeholder="please input the key" required="key is required.">
			  				</div>
			  				<div class="form-group">
			  					<input type="text" class="form-control" name="field"
			  						 placeholder="please input the field" required="field is required.">
			  				</div>
			  				<button type="button" class="btn btn-success" onclick="saveNode('set')">Save</button>
		  					<span class="error"></span>
		  				</div>
		  				<div class="row">
		  					<textarea rows="4" cols="30" name="value" class="form-control"
		  						placeholder="please input the value" required="value is required."></textarea>
		  				</div>
		  			</div>
		  			<span id="retValue"></span>
 				</form>
 			</div>
 		</div>
	</div>
</div>
<div class="row">
	<div class="panel panel-default">
		<div class="panel-heading">
			<div class="panel-title">Hkeys</div>
		</div>
		<div class="panel-body">
			<form id="hkeysForm">
 					<div class="row navbar-form">
		  				<div class="form-group">
		  					<input type="text" class="form-control" name="key"
		  						 placeholder="please input the key" required="key is required.">
		  				</div>
		  				<button type="button" class="btn btn-success" onclick="saveNode('hkeys')">Fetch</button>
		  				<span class="error"></span>
		  			</div>
		  			<textarea id="retValue" rows="4" cols="30" class="form-control"></textarea>
 				</form>
		</div>
	</div>
</div>
 			
<script type="text/javascript">
$(document).ready(function(){
	
});

function saveNode(formKey){
	var formObj = $("#" + formKey + "Form");
	$(formObj).goAjax({semantic: false, url: '/dev/redis/'+formKey, data:{},
		success: function(jsonData) {
			if(true == jsonData.success){
				if('get' == formKey || 'hget' == formKey || 'hkeys' == formKey){
					$("#retValue",formObj).val(jsonData.message);
				} else {
					$("#retValue",formObj).html(jsonData.message);
				}
			} else {
				$.error(jsonData.message);
			}
		}
	});
}
</script>
